home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / PNL Libraries / MyTrackIdle.p < prev    next >
Encoding:
Text File  |  1994-08-27  |  1.2 KB  |  64 lines  |  [TEXT/PJMM]

  1. unit MyTrackIdle;
  2.  
  3. interface
  4.  
  5.     function IdleSince: longInt;  {TickCount at last no idle time}
  6.     procedure InitTrackIdle;
  7.     procedure FinishTrackIdle;
  8.     procedure TrackIdle;
  9.  
  10. implementation
  11.  
  12.     type
  13.         keyLongMap = array[1..4] of longInt;
  14.  
  15.     var
  16.         lastmoved: longInt;  { Last time the cursor was moved, used for idle timing }
  17.         lastpos: point;
  18.         lastkeymap: keyLongMap;
  19.  
  20.     function IdleSince: longInt;  {TickCount at last no idle time}
  21.     begin
  22.         IdleSince := lastmoved;
  23.     end;
  24.  
  25.     procedure MyGetMouse (var pt: point); { Handles not having quickdraw around }
  26.         var
  27. event:eventRecord;
  28. dummy:boolean;
  29.     begin
  30. dummy:=OSEventAvail(0,event);
  31.         pt := event.where;
  32.     end;
  33.  
  34.     procedure TrackIdle;
  35.         var
  36.             pt: point;
  37.             km: keyLongMap;
  38.     begin
  39.         pt := lastpos;
  40.         MyGetMouse(lastpos);
  41.         if (abs(pt.h - lastpos.h) > 2) or (abs(pt.v - lastpos.v) > 2) then begin
  42.             lastmoved := TickCount;
  43.         end
  44.         else begin
  45.             GetKeys(keyMap(km));
  46.             if (km[1] <> lastkeymap[1]) or (km[2] <> lastkeymap[2]) or (km[3] <> lastkeymap[3]) or (km[4] <> lastkeymap[4]) then begin
  47.                 lastmoved := TickCount;
  48.                 lastkeymap := km;
  49.             end;
  50.         end;
  51.     end;
  52.  
  53.     procedure InitTrackIdle;
  54.     begin
  55.         MyGetMouse(lastpos);
  56.         lastmoved := TickCount;
  57.         GetKeys(keyMap(lastkeymap));
  58.     end;
  59.  
  60.     procedure FinishTrackIdle;
  61.     begin
  62.     end;
  63.  
  64. end.